package com.woniuxy.Cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @auther linke
 * @create 2021-10-21 14:28
 */
@WebServlet("/cookieDemo01")
public class CookieDemo01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取cookie对象
        Cookie cookie = new Cookie("name", "tom");//Set-Cookie: name=tom
       //响应添加cookie对象
        resp.addCookie(cookie);

       /* //set-cookie:name=tom 直接设置响应头
        resp.setHeader("set-cookie","name=jerry");*/
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
